const sqlite3 = require('sqlite3').verbose();
const path = require('path');

const dbPath = path.join(__dirname, 'data', 'pph.sqlite');
const db = new sqlite3.Database(dbPath);

console.log('🔍 检查PPH记录详情...');

// 查询所有记录
db.all("SELECT * FROM pph_records ORDER BY id DESC LIMIT 5", (err, rows) => {
    if (err) {
        console.error('❌ 查询失败:', err);
    } else {
        console.log(`📊 最新5条记录 (共 ${rows.length} 条):`);
        rows.forEach((row, index) => {
            console.log(`\n📝 记录 ${index + 1} (ID: ${row.id}):`);
            console.log(`  日期: ${row.date}`);
            console.log(`  班次: ${row.shift}`);
            console.log(`  产品代码: ${row.product_code}`);
            console.log(`  创建时间: ${row.created_at}`);
            console.log(`  原始数据片段: ${JSON.stringify(row).substring(0, 100)}...`);
        });
    }
    
    // 查询总数
    db.get("SELECT COUNT(*) as count FROM pph_records", (err, row) => {
        if (err) {
            console.error('❌ 计数失败:', err);
        } else {
            console.log(`\n📈 PPH记录总数: ${row.count}`);
        }
        db.close();
    });
});
